package com.example.jiaju.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.jiaju.R;
import com.example.jiaju.databinding.BuildExpertItemBinding;
import com.example.jiaju.entity.Expert;
import com.google.android.material.card.MaterialCardView;

import java.util.List;

public class ExpertAdapter extends RecyclerView.Adapter<ExpertAdapter.MyViewHolder> {
    private List<Expert> expertList;
    private Context context;

    public ExpertAdapter(List<Expert> expertList,Context context) {
        this.expertList = expertList;
        this.context=context;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        BuildExpertItemBinding binding= DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                R.layout.build_expert_item, parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(binding.getRoot());
        myViewHolder.binding=binding;
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        //填充真实数据
        Expert expert=expertList.get(position);
        Glide.with(context).load(expert.getExpertImg()).into(holder.binding.buildExpertItemImg);
        Glide.with(context).load(expert.getExpertHead()).into(holder.binding.buildExpertItemHead);
        holder.binding.buildExpertItemText.setText(expert.getExpertName());
    }

    @Override
    public int getItemCount() {
        return expertList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder{

        BuildExpertItemBinding binding;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
